<cfparam name="f" default="docs">
<cfparam name="page_content" default=" ">
<cfparam name="page_name" default="New Page">
<cfparam name="lyo" default="lyo1">
<cfparam name="dir" default="/">
<cfparam name="showform" default="1">

<!---Replace all illgegal characters in the link title--->
<cfset NewFileName = page_name>
<cfset NewFileName = replace(NewFileName, " ", "_", "ALL")>
<cfset NewFileName = replace(NewFileName, "'", "", "ALL")>
<cfset NewFileName = replace(NewFileName, '"', '', 'ALL')>
<cfset NewFileName = replace(NewFileName, "*", "", "ALL")>
<cfset NewFileName = replace(NewFileName, "&", "", "ALL")>
<cfset NewFileName = replace(NewFileName, "(", "", "ALL")>
<cfset NewFileName = replace(NewFileName, ")", "", "ALL")>
<cfset NewFileName = replace(NewFileName, ";", "", "ALL")>
<cfset NewFileName = replace(NewFileName, ":", "", "ALL")>
<cfset NewFileName = replace(NewFileName, "!", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".htm", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".php", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".asp", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".js", "", "ALL")>            
<cfset NewFileName = replacenocase(NewFileName, ".txt", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".cfm", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".html", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".cgi", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".jpg", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".gif", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".png", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".perl", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".cfc", "", "ALL")>
<cfset NewFileName = replacenocase(NewFileName, ".", "", "ALL")>    
<cfset NewFileName = replacenocase(NewFileName, "@", "", "ALL")>
<cfset NewFileWithExt = NewFileName & '.cfm'>

<cfif fileexists('#request.basepath##f#/#NewFileWithExt#')>
	<div id="messages_error">A page with that name already exists.  Please choose another name.</div>
    <cfinclude template="wizard_settings.cfm">
<cfelse>
	<cfoutput><div id="messages_hints">Adding #request.absolutepath##f#/#NewFileWithExt#</cfoutput></div>
	<cfset lyofile = '#lyo#.html'>
    <cfset lyofile = '#request.adminpath#components/pages/resource/layouts/#lyofile#'>
    <cffile action = "read" file="#lyofile#" variable="page_content">
    
    <cfif isdefined('form.savepage')>
        <!---page not found so write new page and redirect--->
        <cffile action="write" output="#form.page_content#" file="#request.basepath##f##dir##NewFileWithExt#">
        <script>
            $(function() {
                $( "#dialog" ).dialog({
                    autoOpen: true,
                    modal: true,
                    my: "center",
                    at: "center",
                    of: window,
                    width: 550,
                    height: 350
                });
            });
        </script>	
    
        <cffile action = "read" file="#request.basepath##f##dir##NewFileWithExt#" variable="page_content">
        <cfinvoke component="cfcs.common.shared" method="redirect" msg="New page has been saved." url="index.cfm?c=pages&f=#f#&dir=#dir#" />
        <cfset showform = 0>     
    </cfif>
    
    <cfif showform IS 1>
    <cfoutput>
    <form id="theForm" method="post" action="index.cfm?c=pages&a=new3&f=#f#&dir=#dir#&lyo=#lyo#">
    <input name="page_name" type="hidden" value="#page_name#" size="60">
    <textarea name="page_content" id="page_content" style="width: 100%; height: 450px;" class="tinymce">#page_content#</textarea>
    <input type="hidden" name="savepage" id="savepage" value="saveit" />
    </form>
    </cfoutput>
    </cfif>
</cfif>	

<script language="javascript">
var NS = (navigator.appName=="Netscape")?true:false; 
iHeight = (NS)?window.innerHeight:document.body.clientHeight;
iHeight = iHeight - 55; 
document.getElementById('page_content').style.height = iHeight + 'px';
</script>